package com.ruoyi.camp.api;

import com.ruoyi.camp.domain.CCamp;
import com.ruoyi.camp.service.ICCampService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;

@Api(value = "微信营地接口", tags = {"微信营地接口"})
@RestController
@RequestMapping(value = "/wechat/camp")
public class WxCampController extends BaseController {
    @Autowired
    private ICCampService cCampService;


    @ApiOperation("获取营地管理详细信息，并记录点击量")
    @GetMapping(value = "/count/{campId}")
    public AjaxResult getInfoAndUpdateCount(@PathVariable("campId")  String campId){
        return  success(cCampService.wxSelectCampByCampId(campId));
    }

//    获取排序过的营地列表
    @GetMapping("/sort")
    public TableDataInfo list(){
        List<CCamp> list =  cCampService.wxSelectCampSortList();
        return getDataTable(list);
    }
    @ApiOperation("微信查询营地")
    @GetMapping("/list")
    public TableDataInfo list(CCamp cCamp)
    {
        List<CCamp> list = cCampService.selectCCampList(cCamp);
        return getDataTable(list);
    }

    @ApiOperation("微信根据CampId查询营地")
    @GetMapping(value = "/{campId}")
    public AjaxResult getInfo(@PathVariable("campId") String campId)
    {
        return success(cCampService.selectCCampByCampId(campId));
    }

    @ApiOperation("微信新增营地")
    @PostMapping
    public AjaxResult add(@RequestBody CCamp cCamp)
    {
        return success(cCampService.insertCCamp(cCamp));
    }

//    修改营地信息
    @PutMapping
    public AjaxResult edit(@RequestBody CCamp cCamp)
    {
        return toAjax(cCampService.updateCCamp(cCamp));
    }

    @DeleteMapping("/{campId}")
    public AjaxResult remove(@PathVariable String campId)
    {
        return toAjax(cCampService.deleteCCampByCampId(campId));
    }

}
